extern "C" {
    fn __errno_location() -> *mut i32;
    fn strtoll(_: *const i8, _: *mut *mut i8, _: i32) -> i64;
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct errval {
    pub errstr: *const i8,
    pub err: i32,
}
#[no_mangle]
pub extern "C" fn strtonum(
    mut numstr: *const i8,
    mut minval: i64,
    mut maxval: i64,
    mut errstrp: *mut *const i8,
) -> i64 {
    let mut ll: i64 = 0 as i64;
    let mut ep: *mut i8 = std::ptr::null_mut::<i8>();
    let mut error: i32 = 0;
    let mut ev: [errval; 4] = [
        {
            let mut init = errval {
                errstr: std::ptr::null::<i8>(),
                err: 0,
            };
            init
        },
        {
            let mut init = errval {
                errstr: b"invalid\0" as *const u8 as *const i8,
                err: 22,
            };
            init
        },
        {
            let mut init = errval {
                errstr: b"too small\0" as *const u8 as *const i8,
                err: 34,
            };
            init
        },
        {
            let mut init = errval {
                errstr: b"too large\0" as *const u8 as *const i8,
                err: 34,
            };
            init
        },
    ];
    ev[0 as i32 as usize].err = unsafe { *__errno_location() };
    (unsafe { *__errno_location() = 0 });
    if minval > maxval {
        error = 1;
    } else {
        ll = unsafe { strtoll(numstr, &mut ep, 10) };
        if numstr == ep as *const i8 || (unsafe { *ep }) as i32 != '\0' as i32 {
            error = 1;
        } else if ll == -(9223372036854775807 as i64) - 1
            && (unsafe { *__errno_location() }) == 34
            || ll < minval
        {
            error = 2;
        } else if ll == 9223372036854775807 && (unsafe { *__errno_location() }) == 34
            || ll > maxval
        {
            error = 3;
        }
    }
    if !errstrp.is_null() {
        (unsafe { *errstrp = ev[error as usize].errstr });
    }
    (unsafe { *__errno_location() = ev[error as usize].err });
    if error != 0 {
        ll = 0 as i64;
    }
    return ll;
}
